﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.User
{
     [PermissionCheck(false)]
    public partial class CGDMX : BasePage
    {
        private Guid CGDID
        {
            get { return this.GetUrlParam("id") == null ? Guid.Empty : new Guid(this.GetUrlParam("id").ToString()); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                BindData();
        }

        private void BindData()
        {
            using (CGDBLL xBLL = new CGDBLL())
            {
                Dictionary<string, string> dc = new Dictionary<string, string>();
                dc.Add("ID", CGDID.ToString());
                int RecordCount = 0;
                CGDModel entity = xBLL.GetCGD(dc, true, null, null, 1, out RecordCount).FirstOrDefault();
                if (entity != null)
                {
                    liBH.Text = entity.BH.ToString();
                    liBMMC.Text = entity.BMMC;
                    liRYMC.Text = entity.RYName;
                    liCZRYName.Text = entity.CZRYName;
                    liRQ.Text = entity.RQ.ToString("yyyy-MM-dd HH:mm");
                    if (entity.DHSJ!=null)
                    {
                        liDHSJ.Text = entity.DHSJ.Value.ToString("yyyy-MM-dd HH:mm");
                    }
                    liGYS.Text = entity.GYSJC;
                    liHB.Text = "元";
                    liZT.Text = Convert.ToInt32(entity.ZT) == 1 ? "已确定" : "待确定";
                    
                }
            }
            using (CGDMXBBLL cBLL = new CGDMXBBLL())
            {
                List<CGDMXBModel> mxbs = cBLL.GetCGDMXB(CGDID);
                GridView1.DataSource = mxbs;
                GridView1.DataBind();
                liMoney.Text = mxbs.Sum(t => t.SL * t.DJ).Value.ToString("F");
            }
        }
    }
}